﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="YoProgramo.Infrastructure.Tools.PagedList"%>
<%@ Import Namespace="YoProgramo.Domain.Core.Entities"%>
<%@ Import Namespace="YoProgramo.Domain.BusinessLogic.Service"%>
<%@ Import Namespace="YoProgramo.Domain.Core.Interfaces"%>
<%@ Import Namespace="YoProgramo.BusinessLogic.Service"%>
<%@ Import Namespace="Microsoft.Practices.ServiceLocation"%>

    <%
      var serviceComment = ServiceLocator.Current.GetInstance<ICommentService>();
      var s = (IPagedList<IUser>)ViewData.Model;                       
    %>
       
    <table cellpadding=15 width="690px" class="TableAdmin">
      <tr class="TableAdminHead">
        <td>
          Id
        </td>
        <td>
          UserName
        </td>    
        <td>
          Fecha
        </td>
        <td>
          DesHabilitado?
        </td>            
        <td>
          Comentarios
        </td>                 
        <td>
          Acciones
        </td>        
      </tr>
    <%foreach (IUser user in s)
    {
    %>    
      <tr class="rowsimple">
        <td>
          <%=user.Id%>
        </td>
        <td>
          <%=user.UserName %>
        </td>
        <td>
          <%= user.RegisteredAt.ToShortDateString() %>
        </td>         
        <td>
          <%= user.IsLockedOut.ToString() %>
        </td>
        <td>
          <%= serviceComment.GetByUser(user).Count %>
        </td>        
        <td>                         
<%if (user.IsLockedOut) {%>

          <% using (Html.BeginRouteForm("Admin", new { action = "EnableUser", id = user.Id }, FormMethod.Post, new { id = "form-del-" + user.Id.ToString() })) { %>  
           <a href="javascript:" onclick="javascript: $('#form-del-<%= user.Id %>').submit();">Habilitar</a>  
          <% } %>


<%
  } else {%>
          <% using (Html.BeginRouteForm("Admin", new { action = "DisableUser", id = user.Id }, FormMethod.Post, new { id = "form-del-" + user.Id.ToString() })) { %>  
           <a href="javascript:" onclick="javascript: $('#form-del-<%= user.Id %>').submit();">Deshabilitar</a>  
          <% } %>
<%} %>    
          
        </td>
      </tr>      
      <%
    }%>  
    </table>       
           
    <%= Html.Paging<IUser>(s, ViewData["UrlPaging"] as string, "__PAGENUM__")%>

